java print stacktrace to file

47

java print stacktrace to file -

//printStackTrace() can accept PrintWriter or PrintStream as argument
catch (Exception e) {

    PrintWriter pw = new PrintWriter(new File("file.txt"));
    e.printStackTrace(pw);
    pw.close();
}

/*Credits: 
Stackoverflow Users: 
Less (https://stackoverflow.com/users/587318/less)
Qnan (https://stackoverflow.com/users/190670/qnan)*/

Comments

Submit
0 Comments